#!/usr/bin/python
'''
First step in read mapping pipeline.
'''
import sys
import h5py
import numpy as np

# constants.
read_size = 1000000

# usage.
def usage():
	print '''
This is step one in the mapping pipeline. It takes a fasta and qual
or fastq file and splits it into multiple pieces.

Optionally it can save the hdf5 data structure used to represent each
split.

The output will be an hdf5 file for each read file containing an
ordering (synchronized if its paired), the optional sequence and qual
files. It will also output the split fastq or fasta qual pairs.

usage: -paired|single -fq1 file fq2 file | -f1 file -f2 file -q1 file -q2 file -n integer -o dir -h dir [-save]

parameters:
-paired: this will be a paired experiment, both sets of files will be required.
-single: this will be a single experiment, only fq1 or f1,q1 are required.
-n: this indicates how many files this should be decomposed into.
-o: the directory the fasta(q) files will be written too.
-h: the directory the project ham files will be written too.
-save: (option) saves the seq and qual data inside the ham file.
'''
	sys.exit(1)

# parameter parsing.
if "-h" in sys.argv or len(sys.argv) == 1:
	usage()
	
pair_mode = True
file_fq1 = ""
file_fq2 = ""
file_f1 = ""
file_f2 = ""
file_q1 = ""
file_q2 = ""
num_files = -1
dir_fasta = ""
dir_ham = ""
save_info = False
for i in range(len(sys.argv)):
	if sys.argv[i] == "-paired":
		pair_mode = True
	elif sys.argv[i] == "-single":
		pair_mode = False
	elif sys.argv[i] == "-fq1":
		file_fq1 = sys.argv[i+1]
	elif sys.argv[i] == "-fq2":
		file_fq2 = sys.argv[i+1]
	elif sys.argv[i] == "-f1":
		file_f1 = sys.argv[i+1]
	elif sys.argv[i] == "-f2":
		file_f2 = sys.argv[i+1]
	elif sys.argv[i] == "-q1":
		file_q1 = sys.argv[i+1]
	elif sys.argv[i] == "-q2":
		file_q2 = sys.argv[i+1]
	elif sys.argv[i] == "-n":
		num_files = int(sys.argv[i+1])
	elif sys.argv[i] == "-o":
		dir_fasta = sys.argv[i+1]
	elif sys.argv[i] == "-h":
		dir_ham = sys.argv[i+1]
	elif sys.argv[i] == "-save":
		save_info = True
		
		
# call appropriate processing funcion.
		
